7  Step 5 - Check ID on Camera

8 Problem Description

This document explains the process of verifying camera IDs between two datasets: the camera trap setup data and the species records data. The goal is to identify any mismatches or inconsistencies in camera IDs between these datasets.

9 Problem Solving

9.1 Common steps

To solve this issue, we follow some of the first basic steps from previous checks, as using our customized read_sheet function that provides the full paths of all .xlsx files available in order to read the species sheet from all files.

Code
source("R/FUNCTIONS.R")

9.2 Data Loading

We load two datasets from the spreadsheet: 1. Camera trap setup data (ct) 2. Species records data (rec)

Code
# Read camera trap setup data
ct <- read_sheet(sheet = "Camera_trap")

# Read species records data
rec <- read_sheet(sheet = "Species_records_camera")

9.3 Verification Process

The verification process consists of two main checks:

9.3.1 Records to Camera Trap Check

This check identifies any camera IDs in the species records that don’t exist in the camera trap data:

Code
record_to_ct <- purrr::map2(ct, rec, function(c, r) {
  base::setdiff(r$Camera_id, c$Camera_id) |>
    tibble::enframe(name = "Error", value = "Camera_id") |>
    dplyr::mutate(note = "Record without camera on sheet")
}) |>
  purrr::discard(~ nrow(.x) == 0) |>
  dplyr::bind_rows(.id = "Dataset")

head(record_to_ct)
# A tibble: 6 × 4
  Dataset        Error Camera_id           note                          
  <chr>          <int> <chr>               <chr>                         
1 Carlos_Scarlat     1 Trap6_Bueiro84N     Record without camera on sheet
2 Carlos_Scarlat     2 Trap6_Bueiro40N     Record without camera on sheet
3 NERF               1 <NA>                Record without camera on sheet
4 Paludosa           1 PF03_CANINANA_E1_C2 Record without camera on sheet
5 Paludosa           2 PF03_CANINANA_E1_C3 Record without camera on sheet
6 Paludosa           3 PF03_CANINANA_E1_C4 Record without camera on sheet

9.3.2 Camera Trap to Records Check

This check identifies any camera IDs in the camera trap data that don’t have corresponding records:

Code
ct_to_record <- purrr::map2(ct, rec, function(c, r) {
  base::setdiff(c$Camera_id, r$Camera_id) |>
    tibble::enframe(name = "Error", value = "Camera_id") |>
    dplyr::mutate(note = "Camera without record on sheet")
}) |>
  purrr::discard(~ nrow(.x) == 0) |>
  dplyr::bind_rows(.id = "Dataset")

head(ct_to_record)
# A tibble: 6 × 4
  Dataset                   Error Camera_id  note                          
  <chr>                     <int> <chr>      <chr>                         
1 Ana_Delciellos                1 PNSB_cam1a Camera without record on sheet
2 Ana_Delciellos                2 PNSB_cam2c Camera without record on sheet
3 Ana_Delciellos                3 PNSB_cam4b Camera without record on sheet
4 Ana_Delciellos                4 PNSB_cam5a Camera without record on sheet
5 Ana_Delciellos                5 PNSB_cam6a Camera without record on sheet
6 Arteris_Litoral_Sul_IBAMA     1 CAM-0008   Camera without record on sheet

9.4 Output Generation

Finally, we combine both checks and save the results to an Excel file:

Code
record_to_ct |>
  dplyr::bind_rows(ct_to_record) |>
  openxlsx::write.xlsx("Output/check_id_errors.xlsx", asTable = TRUE)

9.5 Results Interpretation

The output file check_id_errors.xlsx contains two types of errors:

  • Camera IDs that appear in species records but not in the camera trap data
  • Camera IDs that appear in the camera trap data but have no corresponding species records

This helps identify potential data entry errors or missing information in either dataset.